<template>
<h4 style="text-align: center;">添加投资项目</h4>
    <table class="table-border" border="1"> 
        <tr>
            <td>投资项目名称</td>
            <td>
                <input type="text"  name="I_Name" v-model="info.I_Name" placeholder="请输入投资项目名称"/>
            </td>
        </tr>
        <tr>
            <td>投资项目总金额</td>
            <td>
                <input type="text" name="I_Budget" v-model="info.I_Budget" placeholder="请输入投资项目总金额"/>
            </td>
        </tr>
        <tr>
            <td colspan="2">
                <input type="button" value="添加"@click="Add" />
            </td>
        </tr>
    </table>
</template>
<script setup lang="ts">
import {useRouter} from 'vue-router'
import {ref} from 'vue'
import axios from 'axios'



const info = ref({
    I_Name:'',
    I_Budget:''
})
const router = useRouter()

const Add = ()=>{
    if(info.value.I_Name==""){
        alert("投资项目名称不能为空！")
        return;
    }
    if(info.value.I_Budget==""){
        alert("投资项目总金额不能为空！")
        return;
    }
    console.log(info.value)
    //发送请求
    axios.post('http://localhost:58758/api/Invest/InvestAdd',
        {
            I_Name:info.value.I_Name,
            I_Budget:info.value.I_Budget
        }        
    )
    .then(res=>{
        if(res.data>0){
            alert("投资项目信息添加成功")
            router.push('/ShowInvert')
        }
        else if
        (res.data==-1){
            alert("投资项目名称已存在")
        }
        else 
        {
            alert("投资项目信息添加失败")
        }
    })
    .catch(err=>{
        console.log(err)
    })
}
</script>